package com.loveto.service;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

public class DialogForPush extends Activity {

	private static final int DIALOG_CUSTOM = 1;
	private String Title;
	private String Body;
	private Dialog customDialogInstance;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		//requestWindowFeature(Window.FEATURE_NO_TITLE); //타이틀바 없애기
		//getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //화면이 꺼지지 않게 해줌
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); //화면 잠금 해제 및 화면 켜기
		
		//getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND); //뒤 화면을 흐리게 만들어줌.
		
		Intent intent = getIntent();
		Title = intent.getStringExtra("Title");
		Body = intent.getStringExtra("Body");
		
		showDialog(DIALOG_CUSTOM);
		
	}

    @Override
    protected Dialog onCreateDialog(int id) {
        Dialog dialog;
        switch(id) {
            case DIALOG_CUSTOM:
                dialog = getCustomDialog();
                customDialogInstance = dialog;
                break;
            default:
            	dialog = null;
            	break;
        }
        return dialog;
    }
	
	private Dialog getCustomDialog() {
        AlertDialog.Builder builder;
        AlertDialog alertDialog;
        
        //팝업 레이아웃 설정
   	 	LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.loveto_dialog_push, null);
   	 	//Title
   	 	((TextView)layout.findViewById(R.id.text_title)).setText(Title);
   	 	//Body
   	 	((TextView)layout.findViewById(R.id.text_body)).setText(Body);
   	 	
        TextView okButton = (TextView)layout.findViewById(R.id.btn_ok);
        okButton.setOnClickListener(new OnClickListener() {
            //구매 버튼 처리
            @Override
            public void onClick(View v) {
            	Intent intentMoveToPage = null;
            	if (Title.equals("러브토 쪽지 도착!")) {
            		intentMoveToPage = new Intent(DialogForPush.this,MessageMainActivity.class);
        		} else {
        			intentMoveToPage = new Intent(DialogForPush.this,JoinedTournamentListActivity.class);
        		}
            	startActivity(intentMoveToPage);
            }
            
        });
        
        TextView cancelButton = (TextView)layout.findViewById(R.id.btn_cancel);
        cancelButton.setOnClickListener(new OnClickListener() {
        	//구매 취소 버튼 처리
            @Override
            public void onClick(View v) {
                customDialogInstance.dismiss();
                finish();
            }
        });
        
        builder = new AlertDialog.Builder(this);
        builder.setView(layout);
        alertDialog = builder.create();
                
        return alertDialog;
    }
	
}
